/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UpdateMachine.java
 *
 * Created on 22-06-2011, 09:51:05
 */
package GUILayer;
import ControlLayer.*;
import ModelLayer.*;
/**
 *
 * @author JesperJensen
 */
public class UpdateMachine extends javax.swing.JFrame {
    private RentalController rentalCon;
    private Machine mac;
    /** Creates new form UpdateMachine */
    public UpdateMachine(Machine newMachine) {
        initComponents();
        rentalCon = new RentalController();
        mac = newMachine;
        updateMachineNoPane1.setEnabled(false);
        updateMachineNoPane1.setText("" + mac.getMachineNo());
        updateMachineNameTextField2.setText("" + mac.getName());
        updateMachineDescriptionTextField3.setText("" + mac.getDescription());
        updateMachinePriceTextField4.setEnabled(false);
        updateMachinePriceTextField4.setText("" + mac.getPrice());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        updateMachineUpdateButton2 = new javax.swing.JButton();
        updateMachineNoLabel1 = new javax.swing.JLabel();
        updateMachineNameLabel2 = new javax.swing.JLabel();
        updateMachineDescriptionLabel3 = new javax.swing.JLabel();
        updateMachinePriceLabel4 = new javax.swing.JLabel();
        updateMachineNameTextField2 = new javax.swing.JTextField();
        updateMachineDescriptionTextField3 = new javax.swing.JTextField();
        updateMachinePriceTextField4 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        updateMachineNoPane1 = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("UpdateMachine"));

        jButton1.setText("Cancel");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        updateMachineUpdateButton2.setText("Update");
        updateMachineUpdateButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateMachineUpdateButton2ActionPerformed(evt);
            }
        });

        updateMachineNoLabel1.setText("Machine No:");

        updateMachineNameLabel2.setText("Machine Name:");

        updateMachineDescriptionLabel3.setText("Description:");

        updateMachinePriceLabel4.setText("Price Pr. Day:");

        updateMachineNameTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateMachineNameTextField2ActionPerformed(evt);
            }
        });

        updateMachineDescriptionTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateMachineDescriptionTextField3ActionPerformed(evt);
            }
        });

        updateMachinePriceTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateMachinePriceTextField4ActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(updateMachineNoPane1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(updateMachineUpdateButton2)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(updateMachineNameLabel2)
                            .addComponent(updateMachineDescriptionLabel3)
                            .addComponent(updateMachinePriceLabel4)
                            .addComponent(updateMachineNoLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                            .addComponent(updateMachinePriceTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                            .addComponent(updateMachineDescriptionTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                            .addComponent(updateMachineNameTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))
                        .addGap(170, 170, 170))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(updateMachineNoLabel1)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(updateMachineNameLabel2)
                    .addComponent(updateMachineNameTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(updateMachineDescriptionLabel3)
                    .addComponent(updateMachineDescriptionTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(updateMachinePriceLabel4)
                    .addComponent(updateMachinePriceTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 81, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(updateMachineUpdateButton2)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void updateMachineUpdateButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateMachineUpdateButton2ActionPerformed
        try{
        mac.setDescription(updateMachineDescriptionTextField3.getText());
        mac.setName(updateMachineNameTextField2.getText());
        }catch(Exception e){
            System.out.println(e.getMessage());
        }
        this.dispose();

        
    }//GEN-LAST:event_updateMachineUpdateButton2ActionPerformed

    private void updateMachineDescriptionTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateMachineDescriptionTextField3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_updateMachineDescriptionTextField3ActionPerformed

    private void updateMachinePriceTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateMachinePriceTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_updateMachinePriceTextField4ActionPerformed

    private void updateMachineNameTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateMachineNameTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_updateMachineNameTextField2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //new UpdateMachine().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel updateMachineDescriptionLabel3;
    private javax.swing.JTextField updateMachineDescriptionTextField3;
    private javax.swing.JLabel updateMachineNameLabel2;
    private javax.swing.JTextField updateMachineNameTextField2;
    private javax.swing.JLabel updateMachineNoLabel1;
    private javax.swing.JTextPane updateMachineNoPane1;
    private javax.swing.JLabel updateMachinePriceLabel4;
    private javax.swing.JTextField updateMachinePriceTextField4;
    private javax.swing.JButton updateMachineUpdateButton2;
    // End of variables declaration//GEN-END:variables
}
